package com.dman.multi.cmd;

import org.apache.pivot.collections.List;
import org.apache.pivot.wtk.Prompt;

import com.dman.multi.core.Download;
import com.dman.multi.ui.DMan;

public class GUIResumeCommand implements Command {
	
	private DMan parent;
	private List<Download> downloadList;

	public GUIResumeCommand(DMan parent, List<Download> downloadList) {
		super();
		this.parent = parent;
		this.downloadList = downloadList;
	}

	@Override
	public void execute() {
		int index = parent.getSelectedTableViewIndex();
		if(index >= 0){
			Download d = downloadList.get(index);
			try {
				if(d.isResumeSupported()){
					d.resume();
					return;
				}
				d.restart();
			} catch (Exception e) {
				Prompt.prompt("Unable to resume download", parent);
			}
		}
	}

}
